var BetList = (function($) {
	/*
	 * Full model, used for copying var colNames = [ 'User Id', 'Bet type',
	 * 'Date', 'Choice', 'Channel', 'Odds', 'Stake', 'Win/Lose', 'Comm', 'Agent
	 * WL', 'Affiliate WL', 'Affiliate Comm', 'Status' ]; var colModel =
	 * [userIdModel,transTypeModel,transDateModel,choideModel,channelIdModel,oddsModel,stakeModel,
	 * winLoseModel,commissionModel,agentWlModel,affiliateWlModel,affiliateCommModel.statusModel];
	 * 
	 */

	var userIdModel = {
		name : 'user_id',
		index : 'user_id',
		width : 60,
		sorttype : "int",
		hidden : true
	};
	var userNameModel = {
		name : 'username',
		index : 'username',
		width : 60,
		sorttype : "string"
	};
	var transTypeModel = {
		name : 'trans_type',
		index : 'trans_type',
		width : 90,
		sorttype : "string"
	};
	var transDateModel = {
		name : 'trans_date',
		index : 'trans_date',
		width : 100,
		sorttype : "string"
	};
	var choideModel = {
		name : 'choice',
		index : 'choice',
		width : 80,
		align : "right",
		sorttype : "string"
	};
	var channelIdModel = {
		name : 'channel_id',
		index : 'channel_id',
		width : 80,
		align : "right",
		sorttype : "int"
	};
	var oddsModel = {
		name : 'odds',
		index : 'odds',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var stakeModel = {
		name : 'stake',
		index : 'stake',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var winLoseModel = {
		name : 'win_lose',
		index : 'win_lose',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var commissionModel = {
		name : 'commission',
		index : 'commission',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var agentWlModel = {
		name : 'agent_win_lose',
		index : 'agent_win_lose',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var affiliateWlModel = {
		name : 'affiliate_win_lose',
		index : 'affiliate_win_lose',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var affiliateCommModel = {
		name : 'affiliate_commission',
		index : 'affiliate_commission',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var statusModel = {
		name : 'status',
		index : 'status',
		width : 80,
		align : "center",
		sorttype : "string",
		formatter : 'string'
	};

	return {

		initBetList : function() {
			$("#submit").click(function() {
				BetList.bindBetList();
				return false;
			});
			Agent.initDateRangePicker();
		},

		bindBetList : function() {

			var colNames = [ 'User Id', 'User', 'TransType', 'Date', 'Choice',
					'Channel', 'Odds', 'Stake', 'Win/Lose', 'Comm', 'Agent WL',
					'Status' ];
			var colModel = [ userIdModel, userNameModel, transTypeModel,
					transDateModel, choideModel, channelIdModel, oddsModel,
					stakeModel, winLoseModel, commissionModel, agentWlModel,
					statusModel ];
			var gridOption = $.extend(Agent.gridOption, {
				height : 500,
				colNames : colNames,
				colModel : colModel
			});

			$.blockUI();
			$.ajax( {
				type : "POST",
				url : "bethistoryData",
				dataType : "json",
				data : {
					fromdate : $("#fromdate").val(),
					todate : $("#todate").val()
				},
				success : function(response) {
					// Show the grid
					gridOption.data = response.Main;
					gridOption.userData = response.Total;

					$("#jqgrid-table").jqGrid('GridUnload');
					$("#jqgrid-table").jqGrid(gridOption);
					Agent.initColumnChooser();

				},
				complete : function() {
					$.unblockUI()
				}
			});
		}
	};
})(jQuery);
